
/**
 * @Project : Clion_ProgrammingExercises
 * @File : 0799
 * @Author : WangRuoyu 
 * @Date : 2023/9/15 16:00
 */

#include "iostream"
#include "vector"

using namespace std;

const int N = 1e5 + 10;
int cnt[N];

int main() {
    int n;
    scanf("%d", &n);

    int a[n];
    for (int i = 0; i < n; ++i) {
        scanf("%d", &a[i]);
    }

    int i = 0, j = 0;
    int res = 0;
    for (; j < n; ++j) {
        cnt[a[j]]++;
        if (cnt[a[j]] > 1) {
            res = max(res, j - i);
            while (a[i] != a[j]) {
                cnt[a[i]]--;
                i++;
            }
            cnt[a[i]]--;
            i++;
        }
    }

    res = max(res, j - i);

    printf("%d", res);
    return 0;
}